<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>es6的展开运算符</title>
</head>
<body>
    <script>
        // 展开运算符的基本用法
        const arr1 = [1, 2, 3];
        const arr2 = [4, 5, 6];
        const arr3 = [...arr1, ...arr2]; // [1, 2, 3, 4, 5, 6]
        console.log(arr3);

        // 展开运算符可以用于函数参数
        var test = (... arr)=> {
            console.log(arr); // [1, 2, 3]
        }
        test(1, 2, 3);

        var test1 = (a, b, c)=>{
            console.log(a, b, c); // 1 2 3
        }
        test1(...[1, 2, 3]); 

        function test3() {
            console.log([...arguments]); 
        }
        test3(1, 2, 3); // [1, 2, 3]

        //对象的展开运算符
        const obj1 = { a: 1, b: 2 };
        const obj2 = { c: 3, d: 4 };
        const obj3 = { ...obj1, ...obj2 }; // { a: 1, b: 2, c: 3, d: 4 }
        console.log(obj3);
    </script>
</body>
</html>